@extends('layouts.back_stage')
@section('style')
    <style>
        /*商品资料*/
        .head_p{width:600px;margin:0 auto;font-size:17px;}
        .sel_lab{width:220px;line-height:30px;margin-right:10px;margin-bottom: 15px;font-size:13px;}
        .pro_sel{width:160px;height: 30px;line-height:30px;float:right;outline:none;font-size: 13px;padding:5px 10px;font-weight: normal;border-radius: 2px;color: #555;background:#fff;background-image: none;border: 1px solid #cfdadd;box-shadow: none;}
        .bt_inquire{text-align: center;float:right;display:inline-block;margin-right:19px;}

        .material-choose{width:100%;line-height:30px;height:30px;margin:20px auto;}
        .material_div{width:100%;margin:0 auto;}
        .material{border-collapse:collapse;width:100%;font-size:14px;color:#383838;background:#fff;}
        .material td{text-align:center;height:35px;}
        table,th,td{border:1px solid #ccc;}
        .mask{
            width:100%;
            height:100%;
            position:fixed;
            top:0;
            left:0;
            background-color:rgba(60,60,60,0.8);
            z-index: 99999;
            text-align: center;
            display: none;
        }
        .mask_box{
            position:absolute;
            width:300px;
            height:200px;
            left:50%;
            top:50%;
            margin-left:-150px;
            margin-top:-100px;
            z-index: 999999;
            background: white;
            -webkit-box-shadow: 0px 0px 10px  #000;
            -moz-box-shadow: 0px 0px 10px  #000;
            box-shadow: 0px 0px 10px  #000;
            border-radius: 5px;
            padding-top:20px;
        }
        .mask_box p{
            font-size:20px;
        }
        .mask_box select{
            width:200px;
            margin:0 auto;
        }
        .mask_box button{
            margin:30px;
        }
    </style>
@section('content')
    <div class="container">
        <div style="padding:20px 0;"><h3>投产总计划</h3></div>
        <ul class="pro-ul">
            {{--商品资料--}}
            <li id="capital" class="pro-li">
                <form role="form" action="/admin/operation/put_allPlan" method="get">
                    {{--{{ csrf_field() }}--}}
                    <p class="head_p" style="width:100%;">
                        <label class="sel_lab">季节：
                            <select class="pro_sel pro_opt" name="season">
                                @if($request_infos['season']=='春')
                                    <option value="春">春</option>
                                    <option value="">请选择</option>
                                    <option value="夏">夏</option>
                                    <option value="秋">秋</option>
                                    <option value="冬">冬</option>
                                @elseif($request_infos['season']=='夏')
                                    <option value="夏">夏</option>
                                    <option value="">请选择</option>
                                    <option value="春">春</option>
                                    <option value="秋">秋</option>
                                    <option value="冬">冬</option>
                                @elseif($request_infos['season']=='秋')
                                    <option value="秋">秋</option>
                                    <option value="">请选择</option>
                                    <option value="春">春</option>
                                    <option value="夏">夏</option>
                                    <option value="冬">冬</option>
                                @elseif($request_infos['season']=='冬')
                                    <option value="冬">冬</option>
                                    <option value="">请选择</option>
                                    <option value="春">春</option>
                                    <option value="夏">夏</option>
                                    <option value="秋">秋</option>
                                @else
                                    <option value="">请选择</option>
                                    <option value="春">春</option>
                                    <option value="夏">夏</option>
                                    <option value="秋">秋</option>
                                    <option value="冬">冬</option>
                                @endif

                            </select>
                        </label>
                        <label class="sel_lab">
                            波段：<input type="text" class="pro_sel pro_txt" value="{{ $request_infos['band'] }}" name="band">
                        </label>
                        <label class="sel_lab">款号：<input type="text" class="pro_sel pro_txt" name="girard" value="{{$request_infos['girard']}}"></label>
                        <button type="submit" class="btn bt_del btn-info bt_inquire" style="float:none;">搜索</button>
                </form>
                <div class="material-choose">
                    <span>共<span>{{ $infos_count }}</span>条</span>
                    <a class="btn bt_a1 bt_a" href="javascript:;" onclick="delMaterial()">删除</a>
                    <a class="btn btn-info bt_a" href="javascript:;" onclick="revampDetails()">查看</a>
                    <a class="btn bt_a btn-primary" onclick="addNewPut()">添加</a>
                    <a class="btn bt_a1 bt_a" href="javascript:;" onclick="proVersa()">反审</a>
                    <a class="btn btn-primary bt_a" href="javascript:;" onclick="proAudit()">审核</a>
                </div>
                <div class="material_div">
                    <table class="material" border="1" cellspacing="0" cellpadding="0">
                        <tr>
                            <td style="width:35px;"></td><td>计划单号</td><td>波段</td><td>品类</td><td>款号</td><td>季节</td><td>投产总量</td>
                            <td>已投产</td><td>剩余量</td><td>投产状态</td><td>投产时间</td><td>输入人</td>
                        </tr>
                        @if(count($datas) > 0)
                            @foreach($datas as $k => $v)
                        <tr>
                            {{--<td><input type="checkbox" class="gouMaterial" value="{{ $v->id }}"></td>--}}
                            <td><input type="radio" name="radiomaterial" class="gouMaterial" value="{{ $v->id }}"></td>
                            <td>{{ $v->plan_code }}</td>
                            <td>{{ $v->band_name }}</td>
                            <td>{{ $cate[$v->cate_id] }}</td>
                            <td class="girard">{{ $v->girard }}</td>
                            <td>{{$v->season}}</td>
                            <td>{{$v->total}}</td>
                            <td>
                                @if($v->status == 4)
                                    {{$v->total - $v->surplus_pur }}
                                    @else
                                    0
                                @endif
                              </td>
                            <td>{{$v->surplus_pur}}</td>
                                @if($v->status == 1)
                                <td class="inred" style="color:#ff0000">未审核</td>
                                    @elseif($v->status == 2)
                                <td class="inred" style="color:#00a2d4">已审核</td>
                                    @elseif($v->status == 3)
                                <td class="inred">已核料</td>
                                    @elseif($v->status == 4)
                                <td class="inred">已投产</td>
                                    @elseif($v->status == -1)
                                <td class="inred" style="color:#ff0000">未通过</td>
                                @endif
                            <td>{{ $v->investment_at}}</td>
                            <td>{{ $v->user_name }}</td>
                        </tr>
                            @endforeach
                            @endif
                    </table>
                </div>
                <span style="float: right"><div class="return_box" style="float: right;margin:20px 0;"><button class="btn btn-info" onclick="returnPage()" style="float:right;">跳转</button><input type="text" class="form-control returnPage" style="width:6rem;float: right;margin:0 5px;"></div>{{$datas->appends(['season'=>$request_infos['season'],'girard'=>$request_infos['girard'],'band'=>$request_infos['band']])->links()}}</span>
            </li>
        </ul>
    </div>
    <div class="mask">
        <div class="mask_box">
            <p>请选择要添加的款号</p>
            <select class="form-control" id="getGirard">
                <option value="">请选择</option>
                @if(count($girard) > 0)
                    @foreach($girard as $k => $v)
                        <option value="{{ $v->girard }}">{{ $v->girard }}</option>
                        @endforeach
                    @endif
            </select>
            <button class="btn btn-info" onclick="removeMask()">取消</button><button class="btn btn-info gotoNew">确定</button>
        </div>
    </div>
    <script type="text/javascript">
        //渲染
        $(document).ready(function () {
            if($('.material-choose span span').text() < 10){
                $('.return_box').hide();
            }else{
                $('.return_box').show();
            }
        });
        //点添加唤醒mask层
        function addNewPut() {
            $('.mask').show();
        }
        //生成id跳转添加页面
        $('.gotoNew').click(function () {
            var id = $('#getGirard').val();
            if(id == ""){
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text('请选择款号！');
                $(".oSuccess").show(0).delay(1000).hide(0);
                return false;
            }
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type: 'post',
                url: '/production/createInvestment',
                dataType: 'json',
                data: {
                    sign: 1,
                    girard:id
                },
                success: function (event) {
                    if(event.success){
                        window.location.href = '/production/createView?id=' + event.info
                    }else{
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text(event.msg);
                        $(".oSuccess").show(0).delay(1000).hide(0);
                    }

                }
            })
        });
        //关闭mask层次
        function removeMask() {
            $('.mask').hide();
        }
        //点击查看跳转到修改页面
        function revampDetails() {
            var n=0;
            var id;
            var getInred;
            for(var i=0; i< $(".gouMaterial").length;i++){
                if($(".gouMaterial")[i].checked){
                    id =$(".gouMaterial")[i].value;
                    getInred = $(".gouMaterial").eq(i).parent().siblings('.inred');
                    n++;
                }
            }
            if(n<=1 && n>0){
                window.location.href="/production/createView?id="+id;
            }else{
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请选择单条信息查询");
                $(".oSuccess").show(0).delay(1000).hide(0);
            }
        }
        //删除
        function delMaterial() {
            var n=0;
            var id;
            var getStatus;
            for(var i=0; i< $(".gouMaterial").length;i++){
                if($(".gouMaterial")[i].checked){
                    id =$(".gouMaterial")[i].value;
                    getStatus = $('.gouMaterial').eq(i).parent().siblings('.inred');
                    n++;
                }
            }
            if(n<=1 && n>0){
                if(getStatus.text() == "已投产"){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text('已投产不能再删除');
                    $(".oSuccess").show(0).delay(1500).hide(0);
                    return false;
                }
                $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    type: 'post',
                    url: '/admin/updateInvestStatus',
                    dataType: 'json',
                    data:{
                        status:-2,
                        id:id
                    },
                    success:function (res) {
                        if(res.success){
                            $(".faceImg").attr("src","/img/laugh.png");
                            $(".oHandle").text('删除成功');
                            $(".oSuccess").show(0).delay(1000).hide(0);
                            setTimeout(function(){
                                window.location.reload();
                            },500);
                        }
                    }
                })
            }else{
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请选择一项进行删除");
                $(".oSuccess").show(0).delay(1000).hide(0);
            }
        }
        //审核
        function proAudit() {
            var n=0;
            var id;
            var getStatus;
            for(var i=0; i< $(".gouMaterial").length;i++){
                if($(".gouMaterial")[i].checked){
                    id =$(".gouMaterial")[i].value;
                    getStatus = $('.gouMaterial').eq(i).parent().siblings('.inred');
                    n++;
                }
            }
            if(n<=1 && n>0){
                if(getStatus.text() == "已审核"){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text('已审核的不能再审核');
                    $(".oSuccess").show(0).delay(1500).hide(0);
                    return false;
                }else if(getStatus.text() == "未通过"){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text('未通过的不能再审核');
                    $(".oSuccess").show(0).delay(1500).hide(0);
                    return false;
                }else if(getStatus.text() == "已核料"){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text('已核料的的不能再审核');
                    $(".oSuccess").show(0).delay(1500).hide(0);
                    return false;
                }else if(getStatus.text() == "已投产"){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text('已投产的不能再审核');
                    $(".oSuccess").show(0).delay(1500).hide(0);
                    return false;
                }
                $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    type: 'post',
                    url: '/admin/updateInvestStatus',
                    dataType: 'json',
                    data:{
                        status:2,
                        id:id
                    },
                    success:function (res) {
                        if(res.success){
                            getStatus.text('已审核');
                            getStatus.css('color','#00a2d4');
                        };
                    }
                })
            }else{
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请选择一项进行审核");
                $(".oSuccess").show(0).delay(1000).hide(0);
            }

        }
        //反审
        function proVersa(){
            var n=0;
            var id;
            var getStatus;
            for(var i=0; i< $(".gouMaterial").length;i++){
                if($(".gouMaterial")[i].checked){
                    id =$(".gouMaterial")[i].value;
                    getStatus = $('.gouMaterial').eq(i).parent().siblings('.inred');
                    n++;
                }
            }
            if(n<=1 && n>0){
                if(getStatus.text() == "已审核"){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text('已审核的不能再反审');
                    $(".oSuccess").show(0).delay(1500).hide(0);
                    return false;
                }else if(getStatus.text() == "未通过"){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text('未通过的不能再反审');
                    $(".oSuccess").show(0).delay(1500).hide(0);
                    return false;
                }else if(getStatus.text() == "已核料"){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text('已核料的的不能再反审');
                    $(".oSuccess").show(0).delay(1500).hide(0);
                    return false;
                }else if(getStatus.text() == "已投产"){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text('已投产的不能再反审');
                    $(".oSuccess").show(0).delay(1500).hide(0);
                    return false;
                }
                $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                    },
                    type: 'post',
                    url: '/admin/updateInvestStatus',
                    dataType: 'json',
                    data:{
                        status:-1,
                        id:id
                    },
                    success:function (res) {
                        if(res.success){
                            getStatus.text('未通过');
                            getStatus.css('color','#ff0000');
                        };
                    }
                })
            }else{
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text("请选择一项进行反审");
                $(".oSuccess").show(0).delay(1000).hide(0);
            }

        }
    </script>
@endsection
